package beanstao.util.socket;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 一个状态管理器。主要是对ThreadPoolExecutor的封装。
 * 
 * @author beanstao@google.com 
 * 
 */
public class StatusManager
{

	private final ThreadPoolExecutor threadPool;
	private final long originalStartTime;

	public StatusManager(ThreadPoolExecutor threadPool)
	{
		this.threadPool = threadPool;
		this.originalStartTime = System.currentTimeMillis();
	}

	public long getWorkerPoolSize()
	{
		return this.threadPool.getPoolSize();
	}

	public long getActiveWorkersCount()
	{
		return this.threadPool.getActiveCount();
	}

	public long getUptime()
	{
		return (System.currentTimeMillis() - this.originalStartTime) / 1000;
	}

	public String getFormattedUptime()
	{
		long time = this.getUptime();
		long days = time / 86400;
		long hours = (time / 3600) - (days * 24);
		long minutes = (time / 60) - (days * 1440) - (hours * 60);
		long seconds = time % 60;
		return String.format("%d days, %d hours, %d minutes, %d seconds", days, hours, minutes, seconds);
	}

}
